package com.dwxt.cdms.service;

import com.alibaba.fastjson.JSON;
import com.dwxt.cdms.constant.YMConstantData;
import com.dwxt.cdms.dao.EquipmentCustomMapper;
import com.dwxt.cdms.dao.yumeng.*;
import com.dwxt.cdms.entity.ElectronicFence;
import com.dwxt.cdms.entity.yumeng.LogData;
import com.dwxt.cdms.entity.yumeng.ReceiveData;
import com.dwxt.cdms.util.GpsUtils;
import com.dwxt.cdms.view.EquipmentCustomView;
import com.dwxt.cdms.view.wristwatch.*;
import com.dwxt.cdms.vo.SelectEquipmentCustomVo;
import com.dwxt.cdms.vo.SelectLocDataVo;
import com.dwxt.cdms.vo.SelectWatchDataVo;
import com.dwxt.cdms.vo.SelectWatchVo;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.HttpUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 腕表-健康数据
 *
 * @author Kuang.JiaZhuo
 * @date 2020-09-11 14:12
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WatchService {

    private final BpDataMapper bpDataMapper;
    private final BtDataMapper btDataMapper;
    private final ExdeviceDataMapper exdeviceDataMapper;
    private final HrDataMapper hrDataMapper;
    private final LocDataMapper locDataMapper;
    private final LogDataMapper logDataMapper;
    private final LogRelationMapper logRelationMapper;
    private final ReceiveDataMapper receiveDataMapper;
    private final SleepAnalysisDataMapper sleepAnalysisDataMapper;
    private final SleepAnalysisResultMapper sleepAnalysisResultMapper;
    private final SleepAnalysisStatisticsMapper sleepAnalysisStatisticsMapper;
    private final SleepAnalysisTimeSlotMapper sleepAnalysisTimeSlotMapper;
    private final SleepDataMapper sleepDataMapper;
    private final StepDataMapper stepDataMapper;
    private final UserDataMapper userDataMapper;
    private final EquipmentCustomService equipmentCustomService;
    private final ElectronicFenceService electronicFenceService;
    private final OuFu2Service ouFuService;
    private final StationService stationService;
    private final EquipmentCustomMapper equipmentCustomMapper;
    private final LbWatchService lbWatchService;


    /**
     * @方法名：pageStepDataViewList
     * @描述： 查询-腕表计步数据-带分页
     * @作者： kjz
     * @日期： Created in 2020/9/11 14:31
     */
    public PageInfo<StepDataView> pageStepDataViewList(SelectWatchDataVo selectWatchDataVo) {
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<Integer> customerIds = stepDataMapper.selectCustomerIdsByGroup(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(customerIds);
        List<StepDataView> list = new ArrayList<>();
        customerIds.forEach(customerId -> {
            StepDataView stepDataView = stepDataMapper.selectStepDataViewByNewest(customerId);
            list.add(stepDataView);
        });
        System.err.println(JSON.toJSON(list));
        //按时间降序排序
        if (list.size() > 0) {
            list.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
        }

//        List<StepDataView> list = stepDataMapper.selectStepDataByCondition(selectWatchDataVo);
        //PageInfo<StepDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：pageSleepDataViewList
     * @描述： 查询-腕表睡眠数据-带分页
     * @作者： kjz
     * @日期： Created in 2020/9/11 16:28
     */
    public PageInfo<SleepDataView> pageSleepDataViewList(SelectWatchDataVo selectWatchDataVo) {
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        List<SleepDataView> list = sleepDataMapper.selectSleepDataByCondition(selectWatchDataVo);
        PageInfo<SleepDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：selectSleepDataViewByCondition
     * @描述： 查询-腕表睡眠数据-带分页(纵表转横表)
     * @作者： kjz
     * @日期： Created in 2020/9/12 17:56
     */
    public PageInfo<NewSleepDataView> selectSleepDataViewByCondition(SelectWatchDataVo selectWatchDataVo) {
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<Integer> customerIdList = sleepDataMapper.selectCustomerIdsBySleepData(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(customerIdList);
        List<NewSleepDataView> list = new ArrayList<>();
        customerIdList.forEach(customerId -> {
            NewSleepDataView newSleepDataView = sleepDataMapper.selectSleepDataViewByNewestAndCustomerId(customerId);
            list.add(newSleepDataView);
        });
        //按测量时间降序排序
        list.sort((m1, m2) -> m2.getTime().compareTo(m1.getTime()));
//        List<NewSleepDataView> list = sleepDataMapper.selectSleepDataViewByCondition(selectWatchDataVo);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：pageHrDataViewList
     * @描述： 查询-腕表睡眠数据-带分页
     * @作者： kjz
     * @日期： Created in 2020/9/11 16:50
     */
    public PageInfo<HrDataView> pageHrDataViewList(SelectWatchDataVo selectWatchDataVo) {
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<Integer> customerIdList = hrDataMapper.selectCustomerIdListByCondition(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(customerIdList);
        List<HrDataView> list = new ArrayList<>();
        customerIdList.forEach(customerId -> {
            HrDataView hrDataView = hrDataMapper.selectHrDataViewByCustomerIdAndNewest(customerId);
            list.add(hrDataView);
        });
        //按测量时间降序排序
        list.sort((m1, m2) -> m2.getTime().compareTo(m1.getTime()));
//        List<HrDataView> list = hrDataMapper.selectHrDataViewByCondition(selectWatchDataVo);
        //PageInfo<HrDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }


    /**
     * @方法名：pageBpDataViewList
     * @描述： 按条件查询腕表血压数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/9/11 17:10
     */
    public PageInfo<BpDataView> pageBpDataViewList(SelectWatchDataVo selectWatchDataVo) {
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<Integer> customerIdList = bpDataMapper.selectCustomerIdByCondition(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(customerIdList);
        List<BpDataView> list = new ArrayList<>();
        customerIdList.forEach(customerId -> {
            BpDataView bpDataView = bpDataMapper.selectBpDataViewByCustomerIdAndLatest(customerId);
            list.add(bpDataView);
        });
        //按测量时间降序排序
        list.sort((m1, m2) -> m2.getTime().compareTo(m1.getTime()));
//        List<BpDataView> list = bpDataMapper.selectHrBpDataViewByCondition(selectWatchDataVo);
        //PageInfo<BpDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：pageBtDataViewList
     * @描述： 按条件查询腕表体温数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/9/11 17:42
     */
    public PageInfo<BtDataView> pageBtDataViewList(SelectWatchDataVo selectWatchDataVo) {
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<Integer> customerIdList = btDataMapper.selectCustomerIdsByCondition(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(customerIdList);
        List<BtDataView> list = new ArrayList<>();
        customerIdList.forEach(customerId -> {
            BtDataView btDataView = btDataMapper.selectBtDataViewByCustomerId(customerId);
            list.add(btDataView);
        });
        //按测量时间降序排序
        list.sort((m1, m2) -> m2.getTime().compareTo(m1.getTime()));
//        List<BtDataView> list = btDataMapper.selectBtDataViewByCondition(selectWatchDataVo);
        //PageInfo<BtDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：pageLocDataViewList
     * @描述： 按条件查询腕表定位数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/9/11 18:13
     */
    public PageInfo<LocDataView> pageLocDataViewList(SelectWatchDataVo selectWatchDataVo) {
        if (selectWatchDataVo.getPageSize() == null) {
            selectWatchDataVo.setPageSize(500);
        }
        Integer stationId = stationService.getLoginUserStation();
        PageHelper.startPage(selectWatchDataVo.getPageNum(), selectWatchDataVo.getPageSize());
        if (stationId != null) {
            selectWatchDataVo.setStationId(stationId);
        }
        List<LocDataView> list = locDataMapper.selectLocDataViewByCondition(selectWatchDataVo);
        PageInfo pageInfo = new PageInfo(list);
        list.forEach(locDataView -> {
            //经纬度： WG1984 -> GCJ02
            double[] nautica = GpsUtils.wgs84togcj02(Double.parseDouble(locDataView.getLongitude()), Double.parseDouble(locDataView.getLatitude()));
            locDataView.setLongitude(String.valueOf(nautica[0])).setLatitude(String.valueOf(nautica[1]));

            Integer customerId = locDataView.getCustomerId();
            //开关机状态
            LogData logData = logDataMapper.selectLogDataByCustomerIdAndLatest(customerId);
            if (null != logData && null != logData.getRecordType() && "3".equals(logData.getRecordType())) {
                locDataView.setState(logData.getRecordType());
            }
            //围栏设置
            ElectronicFence electronicFence = electronicFenceService.selectFenceByCustomerId(customerId);
            if (electronicFence != null) {
                locDataView.setIsEnabled(electronicFence.getStatus())
                        .setElectronicArea(electronicFence.getElectronicArea())
                        .setElectronicAreaDouble(electronicFence.getElectronicAreaDouble())
                        .setElectronicFenceId(electronicFence.getId());
            }

        });

        //按测量时间降序排序
        list.sort((m1, m2) -> m2.getTime().compareTo(m1.getTime()));
        //
        // PageInfo<LocDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：deleteWatchDataByCustomerIds
     * @描述： 根据客户id批量删除腕表健康数据
     * @作者： kjz
     * @日期： Created in 2020/9/12 15:09
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteWatchDataByCustomerIds(Integer[] customerIds) {

        for (Integer id : customerIds) {
            if (id == 4 || id == 5) {
                //测试数据暂不删除
                return 0;
            }
        }

        int result = 0;
        //删除血压
        result += bpDataMapper.deleteBpDataByCustomerIds(customerIds);
        //删除体温
        result += this.btDataMapper.deleteBtDataByCustomerIds(customerIds);
        //删除心率
        result += this.hrDataMapper.deleteHrDataByCustomerIds(customerIds);
        //删除定位
        result += this.locDataMapper.deleteLocDataByCustomerIds(customerIds);
        //删除计步
        result += this.stepDataMapper.deleteStepDataByCustomerIds(customerIds);
        //删除睡眠
        result += this.sleepDataMapper.deleteSleepDataByCustomerIds(customerIds);
        //外接设备
        result += this.exdeviceDataMapper.deteleExdeviceDataByCustomerIds(customerIds);
        //删除睡眠分析相关的腕表数据
        result += this.deleteSleepAnalysisDataByCustomerIds(customerIds);
        //删除设备日志相关的腕表数据
        result += this.deleteLogDataByCustomerIds(customerIds);
        return result;
    }

    /**
     * @方法名：deleteLogDataByCustomerIds
     * @描述： 根据客户id删除腕表相关的【设备日志】数据
     * @作者： kjz
     * @日期： Created in 2020/9/12 16:12
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteLogDataByCustomerIds(Integer[] customerIds) {
        int result = 0;
        result += logRelationMapper.deleteDataByCustomerIds(customerIds);
        result += logDataMapper.deleteLogDataByCustomerIds(customerIds);
        return result;
    }

    /**
     * @方法名：deleteSleepDataByCustomerIds
     * @描述： 根据客户id删除腕表相关的【睡眠分析】数据
     * @作者： kjz
     * @日期： Created in 2020/9/12 15:34
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteSleepAnalysisDataByCustomerIds(Integer[] customerIds) {
        int result = 0;
        result += sleepAnalysisTimeSlotMapper.deleteDataByCustomerIds(customerIds);
        result += sleepAnalysisStatisticsMapper.deleteDataByCustomerIds(customerIds);
        result += sleepAnalysisResultMapper.deleteDataByCustomerIds(customerIds);
        result += sleepAnalysisDataMapper.deleteSleepAnalysisByCustomerIds(customerIds);
        return result;
    }


    /**
     * @方法名：replaceBindingWatchUser
     * @描述： 更换手表和用户的绑定
     * @作者： kjz
     * @日期： Created in 2020/9/16 17:29
     */
    @Transactional(rollbackFor = Exception.class)
    public int replaceBindingWatchUser(Integer customerId, String deviceIdentity) {
        int result = 0;
        //睡眠数据
        result += sleepDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //计步数据
        result += stepDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //睡眠分析数据
        result += sleepAnalysisDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //日志数据
        result += logDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //定位数据
        result += locDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //心率数据
        result += hrDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //外接设备数据
        result += exdeviceDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //体温数据
        result += btDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        //血压数据
        result += bpDataMapper.replaceBindingWatchUser(customerId, deviceIdentity);
        return result;
    }


    /**
     * @方法名：deleteWasteDataByWeek
     * @描述： 清除手表废数据
     * @作者： kjz
     * @日期： Created in 2020/9/22 14:25
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteWasteDataByWeek() {
        List<ReceiveData> list = receiveDataMapper.selectReceiveDataByWeek();
        int result = 0;

        for (ReceiveData receiveData : list) {
            String type = receiveData.getType();
            String id = receiveData.getId();
            //睡眠
            if (type.equals(YMConstantData.DATA_TYPE_1)) {
                result += receiveDataMapper.deleteWasteDataByTypeSleep(id);
            }

            //计步
            if (type.equals(YMConstantData.DATA_TYPE_2)) {
                result += receiveDataMapper.deleteWasteDataByTypeStep(id);
            }

            //心率
            if (type.equals(YMConstantData.DATA_TYPE_3)) {
                result += receiveDataMapper.deleteWasteDataByTypeHr(id);
            }

            //血压
            if (type.equals(YMConstantData.DATA_TYPE_4)) {
                result += receiveDataMapper.deleteWasteDataByTypeBp(id);
            }

            //体温
            if (type.equals(YMConstantData.DATA_TYPE_5)) {
                result += receiveDataMapper.deleteWasteDataByTypeBt(id);
            }

            //定位
            if (type.equals(YMConstantData.DATA_TYPE_6)) {
                result += receiveDataMapper.deleteWasteDataByTypeLoc(id);
            }

            //用户
            if (type.equals(YMConstantData.DATA_TYPE_7)) {
                result += receiveDataMapper.deleteWasteDataByTypeUser(id);
            }

            //设备日志
            if (type.equals(YMConstantData.DATA_TYPE_8)) {
                result += receiveDataMapper.deleteWasteDataByTypeLog(id);
            }

            //外接设备
            if (type.equals(YMConstantData.DATA_TYPE_9)) {
                result += receiveDataMapper.deleteWasteDataByTypeExdevice(id);
            }

            //睡眠分析
            if (type.equals(YMConstantData.DATA_TYPE_10)) {
                result += receiveDataMapper.deleteWasteDataByTypeSleepAnalysis(id);
            }
        }

        return result;
    }

    /**
     * @方法名：selectLocDataListByCustomerId
     * @描述： 根据用户id和时间查询用户的运动轨迹
     * @作者： kjz
     * @日期： Created in 2020/9/23 16:31
     */
    public TrackView selectLocDataListByCustomerId(SelectLocDataVo selectLocDataVo) {
        List<MotionTrail> list = locDataMapper.selectLocDataListByCustomerId(selectLocDataVo);
        list.forEach(motionTrail -> {
            double[] nautica = GpsUtils.wgs84togcj02(Double.parseDouble(motionTrail.getLongitude()), Double.parseDouble(motionTrail.getLatitude()));
            motionTrail.setLongitude(String.valueOf(nautica[0])).setLatitude(String.valueOf(nautica[1]));
        });

        LocDataView locDataView = locDataMapper.selectLocDataByCustomerId(selectLocDataVo);

        Optional.ofNullable(locDataView).ifPresent(t -> {
            double[] nautica = GpsUtils.wgs84togcj02(Double.parseDouble(t.getLongitude()), Double.parseDouble(t.getLatitude()));
            t.setLongitude(String.valueOf(nautica[0])).setLatitude(String.valueOf(nautica[1]));
        });
        return new TrackView().setMotionTrails(list).setLocDataView(locDataView);
    }

    /**
     * @方法名：pageStepDataViewListByCustomerId
     * @描述： 按客户id查询腕表计步数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/10/12 15:08
     */
    public PageInfo<StepDataView> pageStepDataViewListByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<StepDataView> list = stepDataMapper.selectStepDataViewListByCustomerId(selectWatchVo);
        PageInfo<StepDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：selectSleepDataViewByCustomerId
     * @描述： 按客户id查询睡眠数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/10/12 16:08
     */
    public PageInfo<NewSleepDataView> selectSleepDataViewByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<NewSleepDataView> list = sleepDataMapper.selectSleepDataViewByCustomerId(selectWatchVo);
        PageInfo<NewSleepDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：pageHrDataViewListByCustomerId
     * @描述： 根据客户id查询腕表心率数据
     * @作者： kjz
     * @日期： Created in 2020/10/12 16:35
     */
    public PageInfo<HrDataView> pageHrDataViewListByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<HrDataView> list = hrDataMapper.selectHrDataViewListByCustomerId(selectWatchVo);
        PageInfo<HrDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：pageBpDataViewListByCustomerId
     * @描述： 按客户id查询腕表血压数据(带分页)
     * @作者： kjz
     * @日期： Created in 2020/10/12 17:20
     */
    public PageInfo<BpDataView> pageBpDataViewListByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<BpDataView> list = bpDataMapper.selectBpDataViewListByCustomerId(selectWatchVo);
        PageInfo<BpDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：pageBtDataViewListByCustomerId
     * @描述： 根据用户id查询腕表体温数据-带分页
     * @作者： kjz
     * @日期： Created in 2020/10/12 17:44
     */
    public PageInfo<BtDataView> pageBtDataViewListByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<BtDataView> list = btDataMapper.selectBtDataViewListByCustomerId(selectWatchVo);
        PageInfo<BtDataView> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @方法名：pageLocDataViewListByCustomerId
     * @描述： 根据客户id查询该客户的历史定位信息
     * @作者： kjz
     * @日期： Created in 2020/10/13 14:59
     */
    public PageInfo<LocDataView> pageLocDataViewListByCustomerId(SelectWatchVo selectWatchVo) {
        PageHelper.startPage(selectWatchVo.getPageNum(), selectWatchVo.getPageSize());
        List<LocDataView> list = locDataMapper.selectLocDataViewListByCustomerId(selectWatchVo);
        PageInfo pageInfo = new PageInfo(list);
        list.forEach(locDataView -> {
            double[] nautica = GpsUtils.wgs84togcj02(Double.parseDouble(locDataView.getLongitude()), Double.parseDouble(locDataView.getLatitude()));
            locDataView.setLongitude(String.valueOf(nautica[0])).setLatitude(String.valueOf(nautica[1]));
        });
        //PageInfo<LocDataView> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);
        return pageInfo;
    }

    /**
     * @方法名：selectLocDataViewByCustomerId
     * @描述： 根据客户id查询该客户的最新的定位信息
     * @作者： kjz
     * @日期： Created in 2020/10/23 16:59
     */
    public Object selectLocDataViewByCustomerId(Integer customerId) {

        equipmentCustomService.selectEquipmentByCustomerId(customerId);

        //OuFuLocData ouFuLocData = ouFuService.selectLastLocDataByType(customerId, ReceiveDataType.WIFI);
        Map map = ouFuService.selectLastLocDataByCustomerId(customerId);
        return map;
     /*   LocDataView locDataView = locDataMapper.selectLocDataViewByCustomerId(customerId);
        if (null != locDataView) {
            String longitude = locDataView.getLongitude();
            String latitude = locDataView.getLatitude();
            if (null != longitude && null != latitude) {
                double[] nautica = GpsUtils.wgs84togcj02(Double.parseDouble(longitude), Double.parseDouble(latitude));
                locDataView.setLongitude(String.valueOf(nautica[0])).setLatitude(String.valueOf(nautica[1]));
            }
        }*/
    }

    public List<NewSleepDataView> selectCustomerSleepDataView(String customerId, Integer scope) {
        return sleepDataMapper.selectCustomerSleepDataView(customerId, scope);
    }

    public List<HrDataView> selectCustomerHrDataView(String customerId, Integer scope) {

        return hrDataMapper.selectCustomerHrDataView(customerId, scope);
    }

    public List<BpDataView> selectCustomerBpDataView(String customerId, Integer scope) {
        return bpDataMapper.selectCustomerBpDataView(customerId, scope);
    }

    public List<BtDataView> selectCustomerBtDataView(String customerId, Integer scope) {
        return btDataMapper.selectCustomerBtDataView(customerId, scope);
    }

    public BaseResult refreshWatchLoc(Integer customerId) {
        SelectEquipmentCustomVo vo = new SelectEquipmentCustomVo();
        vo.setCustomerId(customerId);
        List<EquipmentCustomView> list = equipmentCustomMapper.selectEquipmentCustomList(vo);
        for (EquipmentCustomView equipmentCustomView : list) {
            if (equipmentCustomView.getCategory().equals("4")) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("IMEI", equipmentCustomView.getSerialNumber());
                map.put("CmdCode", "0039");
                String s = HttpUtils.postRequest("http://www.aiday.com.cn:10502/api/Command/SendCommand", map);
            }
            if (equipmentCustomView.getCategory().equals("12")) {
                lbWatchService.openFindElder(equipmentCustomView.getLbUserid());
            }
        }
        return BaseResult.ok();
    }
}
